<?php
/**
 * Application user
 */
class Application_Model_Userprofile extends Zend_Db_Table_Abstract {

    protected $_name = 'user_profiles';
    public $user_id;

    public function  __construct($user_id) {
	$this->user_id = $user_id;
	parent::__construct();
    }

    public function addRecord( $profile_type_id, $first_name, $last_name, $address=null, $city=null, $state=null, $zip=null, $phone=null, $notes=null )
    {
	$insert_data = array(
	    "user_id"		=> $this->user_id,
	    "profile_type_id"	=> $profile_type_id,
	    "first"		=> $first_name,
	    "last"		=> $last_name,
	    "address"		=> $address,
	    "city"		=> $city,
	    "state"		=> $state,
	    "zip"		=> $zip,
	    "phone"		=> $phone,
	    "notes"		=> $notes,
	    "created"		=> new Zend_Db_Expr('CURRENT_TIMESTAMP')
	);
	$profile_id = $this->insert($insert_data);
	return $profile_id;
    }


    public function updateRecord( $profile_type_id, $first_name, $last_name, $address=null, $city=null, $state=null, $zip=null, $phone=null, $notes=null )
    {
	$where = array(
	    $this->getAdapter()->quoteInto('user_profiles.user_id = ?', $this->user_id),
	    $this->getAdapter()->quoteInto('user_profiles.profile_type_id = ?', $profile_type_id)
	);
	// Assemble the update data
	$update_data = array(
	    "first"		=> $first_name,
	    "last"		=> $last_name,
	    "address"		=> $address,
	    "city"		=> $city,
	    "state"		=> $state,
	    "zip"		=> $zip,
	    "phone"		=> $phone,
	    "notes"		=> $notes,
	    "modified"		=> new Zend_Db_Expr('CURRENT_TIMESTAMP')
	);
	$result = $this->update($update_data, $where);
	return $result;
    }

    public function getByType( $profile_type_id )
    {
	$where = array(
	    $this->getAdapter()->quoteInto('user_profiles.user_id = ?', $this->user_id),
	    $this->getAdapter()->quoteInto('user_profiles.profile_type_id = ?', $profile_type_id)
	);
	$select = $this->select()->where($where);
	$result = $this->fetchRow($select);
	return $result;
    }

    public function getAll( )
    {
	$where = array(
	    $this->getAdapter()->quoteInto('user_profiles.user_id = ?', $this->user_id)
	);
	$select = $this->select()->where($where);
	$result = $this->fetchAll($select);
	return $result;
    }

    public function deleteRecord( $profile_type_id )
    {
	$where = array(
	    $this->getAdapter()->quoteInto('user_profiles.user_id = ?', $this->user_id),
	    $this->getAdapter()->quoteInto('user_profiles.profile_type_id = ?', $profile_type_id)
	);
	$result = $this->delete($where);
	return $result;
    }
        
}
